<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>新增员工</title>

    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">


    <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="../plugins/iCheck/square/blue.css">
    <link rel="stylesheet" href="../plugins/morris/morris.css">
    <link rel="stylesheet" href="../plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <link rel="stylesheet" href="../plugins/datepicker/datepicker3.css">
    <link rel="stylesheet" href="../plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet" href="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="../plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="../plugins/treeTable/jquery.treetable.css">
    <link rel="stylesheet" href="../plugins/treeTable/jquery.treetable.theme.default.css">
    <link rel="stylesheet" href="../plugins/select2/select2.css">
    <link rel="stylesheet" href="../plugins/colorpicker/bootstrap-colorpicker.min.css">
    <link rel="stylesheet" href="../plugins/bootstrap-markdown/css/bootstrap-markdown.min.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../plugins/ionslider/ion.rangeSlider.css">
    <link rel="stylesheet" href="../plugins/ionslider/ion.rangeSlider.skinNice.css">
    <link rel="stylesheet" href="../plugins/bootstrap-slider/slider.css">
    <link rel="stylesheet" href="../plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="../js/jwt-decode.js"></script>
</head>

<body class="hold-transition skin-purple sidebar-mini">

    <div class="wrapper">

        <!-- 页面头部 -->
        <header class="main-header">

            <!-- Logo -->
            <a href="common-index.html" class="logo">
                <!-- 侧边栏迷你logo，尺寸为50x50像素 -->
                <span class="logo-mini"><b>电子钱包</b></span>
                <!-- 常规状态和移动设备的logo -->
                <span class="logo-lg"><b>电子钱包</b>后台管理</span>
            </a>

            <!-- 头部导航栏：样式可以在header.less中找到 -->
            <nav class="navbar navbar-static-top">
                <!-- 侧边栏切换按钮 -->
                <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                    <span class="sr-only">Toggle navigation</span>
                </a>

                <div class="navbar-custom-menu">
                    <ul class="nav navbar-nav">

                        <li class="dropdown user user-menu">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                <img src="" class="user-image all-avatar-image">
                                <span class="hidden-xs employee-name"></span>
                            </a>

                            <ul class="dropdown-menu">
                                <!-- 用户图片 -->
                                <li class="user-header">
                                    <img src="" class="img-circle all-avatar-image">

                                    <p class="employee-name"></p>
                                </li>

                                <li class="user-footer">
                                    <div class="pull-left">
                                        <a href="employee-info.html" class="btn btn-default btn-flat">修改信息</a>
                                    </div>
                                    <div class="pull-right">
                                        <a href="javascript:void(0);" class="btn btn-default btn-flat"
                                            id="logoutBtn">退出账号</a>
                                    </div>
                                </li>
                            </ul>
                        </li>

                    </ul>
                </div>
            </nav>
        </header>
        <!-- 页面头部 /-->

        <!-- 导航侧栏 -->
        <aside class="main-sidebar">
            <!-- 侧边栏：样式可以在sidebar.less中找到 -->
            <section class="sidebar">
                <!-- 侧边栏用户面板 -->
                <div class="user-panel">
                    <div class="pull-left image">
                        <img src="" class="img-circle all-avatar-image">
                    </div>
                    <div class="pull-left info">
                        <p class="employee-name"></p>
                        <a href="#"><i class="fa fa-circle text-success"></i> 在线</a>
                    </div>
                </div>

                <ul class="sidebar-menu">
                    <li class="header">菜单</li>

                    <li id="admin-index"><a href="common-index.html"><i class="fa fa-dashboard"></i> <span>首页</span></a>
                    </li>

                    <!-- 菜单 -->

                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-folder"></i>
                            <span>系统管理</span>
                            <span class="pull-right-container">
                                <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">

                            <li id="admin-role-manage">
                                <a href="role-list.html">
                                    <i class="fa fa-circle-o"></i> 角色管理
                                </a>
                            </li>

                            <li id="admin-datalist">
                                <a href="employee-list.html">
                                    <i class="fa fa-circle-o"></i> 员工管理
                                </a>
                            </li>

                            <li id="admin-user-manage">
                                <a href="user-list.html">
                                    <i class="fa fa-circle-o"></i> 用户管理
                                </a>
                            </li>

                            <li id="admin-profile">
                                <a href="employee-info.html">
                                    <i class="fa fa-circle-o"></i> 个人中心
                                </a>
                            </li>

                        </ul>
                    </li>



                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-pie-chart"></i> <span>业务管理</span>
                            <span class="pull-right-container">
                                <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">

                            <li id="history-list">
                                <a href="history-list.html">
                                    <i class="fa fa-circle-o"></i> 历史记录管理
                                </a>
                            </li>

                        </ul>
                    </li>

                </ul>
            </section>

        </aside>
        <!-- 导航侧栏 /-->

        <!-- 内容区域 -->
        <!-- @@master = admin-layout.html-->
        <!-- @@block = content -->

        <div class="content-wrapper">

            <!-- 内容头部 -->
            <section class="content-header">
                <h1>
                    员工管理
                    <small>新增员工</small>
                </h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                    <li><a href="#">员工管理</a></li>
                    <li class="active">新增员工</li>
                </ol>
            </section>
            <!-- 内容头部 /-->

            <!-- 正文区域 -->
            <section class="content">

                <div class="box-body">

                    <!--tab页-->
                    <div class="nav-tabs-custom">

                        <!--tab头-->
                        <ul class="nav nav-tabs">
                            <li class="active">
                                <a href="#tab-label" data-toggle="tab">员工信息详情</a>
                            </li>
                        </ul>
                        <!--tab头/-->

                        <!--tab内容-->
                        <div class="tab-content">

                            <!--label显示的内容-->
                            <div class="tab-pane active" id="tab-label">

                                <div class="row data-type">

                                    <div class="col-md-2 title">姓名</div>
                                    <div class="col-md-4 data">
                                        <input type="text" class="form-control" placeholder="姓名" id="name"
                                            maxlength="12">
                                    </div>

                                    <div class="col-md-2 title">英文名</div>
                                    <div class="col-md-4 data">
                                        <input type="text" class="form-control" placeholder="英文名" id="englishName"
                                            maxlength="20">
                                    </div>

                                    <div class="col-md-2 title">邮箱</div>
                                    <div class="col-md-4 data">
                                        <input type="text" class="form-control" placeholder="邮箱" id="email"
                                            maxlength="30">
                                    </div>

                                    <div class="col-md-2 title">联系电话</div>
                                    <div class="col-md-4 data">
                                        <input type="text" class="form-control" placeholder="联系电话" id="phone"
                                            maxlength="11">
                                    </div>

                                    <div class="col-md-2 title">性别</div>
                                    <div class="col-md-4 data">
                                        <div class="input-group">
                                            <select class="form-control" id="gender">
                                                <option value="男">男</option>
                                                <option value="女">女</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-2 title">生日</div>
                                    <div class="col-md-4 data">
                                        <input type="date" class="form-control" placeholder="生日" id="bornDate">
                                    </div>

                                    <div class="col-md-12 data text-center">
                                        <button type="button" class="btn bg-maroon" onclick="saveEmployee()">保存</button>
                                        <button type="button" class="btn bg-default"
                                            onclick="history.back(-1);">返回</button>
                                    </div>
                                </div>

                            </div>

                            <!--基础控件/-->
                        </div>
                        <!--tab内容/-->

                    </div>
                    <!--tab页/-->

                </div>

            </section>
            <!-- 正文区域 /-->

        </div>
        <!-- @@close -->
        <!-- 内容区域 /-->

        <!-- 底部导航 -->
        <footer class="main-footer">
            <strong>Copyright &copy; <a href="">电子钱包</a>.</strong> All rights reserved.
        </footer>
        <!-- 底部导航 /-->

    </div>

    <script type="text/javascript">

        // 顶部与侧边栏信息渲染,注销按钮
        $(document).ready(function () {
            var token = localStorage.getItem('token');
            var longToken = localStorage.getItem('longToken');

            // 获取注销按钮
            var logoutBtn = $("#logoutBtn");

            // 为注销按钮添加点击事件
            logoutBtn.click(function () {
                // 清除本地存储的 token 和 longToken
                localStorage.removeItem('token');
                localStorage.removeItem('longToken');
                // 跳转到登录
                window.location.href = 'employee-login.html';
            });

            if (token && longToken) {
                var decoded = jwt_decode(longToken);
                var userId = decoded.userId;

                getInfo(userId, token, longToken);
            } else {
                // 跳转到登录页面
                window.location.href = 'employee-login.html';
            }
        });

        // 获取个人数据，渲染侧边栏和头部
        function getInfo(userId, token, longToken) {
            var url = 'http://localhost:8080/employee/findByIdController?userId=' + userId;

            if (token && longToken) {
                url += '&token=' + token + '&longToken=' + longToken;
            }

            // 发送 AJAX 请求获取数据
            $.ajax({
                url: url,
                method: 'get',
                success: function (result) {

                    if (result.code === 200) {
                        var datas = result.datas;
                        var imageUrl = "http://localhost:8080/" + datas.imageAddress;

                        var imgs = document.querySelectorAll('img.all-avatar-image');
                        imgs.forEach(function (img) {
                            img.src = imageUrl;
                        });

                        var elements = document.querySelectorAll('.employee-name');
                        elements.forEach(function (el) {
                            el.innerHTML = datas.userName;
                        });

                    } else if (result.code === 6000 || result.code === 4000) {
                        // 跳转到登录
                        window.location.href = 'employee-login.html';
                    } else {
                        alert("获取数据失败");
                    }

                },
                error: function (xhr, status, error) {
                    console.log("请求失败");
                }
            });
        }
    </script>



    <script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="../plugins/jQueryUI/jquery-ui.min.js"></script>
    <script>
        $.widget.bridge('uibutton', $.ui.button);
    </script>
    <script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="../plugins/raphael/raphael-min.js"></script>
    <script src="../plugins/morris/morris.min.js"></script>
    <script src="../plugins/sparkline/jquery.sparkline.min.js"></script>
    <script src="../plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
    <script src="../plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
    <script src="../plugins/knob/jquery.knob.js"></script>
    <script src="../plugins/daterangepicker/moment.min.js"></script>
    <script src="../plugins/daterangepicker/daterangepicker.js"></script>
    <script src="../plugins/daterangepicker/daterangepicker.zh-CN.js"></script>
    <script src="../plugins/datepicker/bootstrap-datepicker.js"></script>
    <script src="../plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
    <script src="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
    <script src="../plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <script src="../plugins/fastclick/fastclick.js"></script>
    <script src="../plugins/iCheck/icheck.min.js"></script>
    <script src="../plugins/adminLTE/js/app.min.js"></script>
    <script src="../plugins/treeTable/jquery.treetable.js"></script>
    <script src="../plugins/select2/select2.full.min.js"></script>
    <script src="../plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <script src="../plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.zh-CN.js"></script>
    <script src="../plugins/bootstrap-markdown/js/bootstrap-markdown.js"></script>
    <script src="../plugins/bootstrap-markdown/locale/bootstrap-markdown.zh.js"></script>
    <script src="../plugins/bootstrap-markdown/js/markdown.js"></script>
    <script src="../plugins/bootstrap-markdown/js/to-markdown.js"></script>
    <script src="../plugins/ckeditor/ckeditor.js"></script>
    <script src="../plugins/input-mask/jquery.inputmask.js"></script>
    <script src="../plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
    <script src="../plugins/input-mask/jquery.inputmask.extensions.js"></script>
    <script src="../plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../plugins/datatables/dataTables.bootstrap.min.js"></script>
    <script src="../plugins/chartjs/Chart.min.js"></script>
    <script src="../plugins/flot/jquery.flot.min.js"></script>
    <script src="../plugins/flot/jquery.flot.resize.min.js"></script>
    <script src="../plugins/flot/jquery.flot.pie.min.js"></script>
    <script src="../plugins/flot/jquery.flot.categories.min.js"></script>
    <script src="../plugins/ionslider/ion.rangeSlider.min.js"></script>
    <script src="../plugins/bootstrap-slider/bootstrap-slider.js"></script>
    <script src="../plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
    <script src="../plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>\


    <script>

        function saveEmployee() {
            var token = localStorage.getItem('token');
            var longToken = localStorage.getItem('longToken');

            if (!(token && longToken)) {
                // 跳转到登录页面
                window.location.href = 'employee-login.html';
            }

            var name = $("#name").val();
            var englishName = $("#englishName").val();
            var email = $("#email").val();
            var phone = $("#phone").val();
            var gender = $("#gender").val();
            var bornDate = $("#bornDate").val();

            // 判断姓名格式是否正确
            if (name.trim() === "" || !/^[\u4e00-\u9fa5]+$/.test(name)) {
                alert('姓名格式不正确');
                return;
            }

            // 判断英文名是否为空或者包含数字或中文
            if (englishName.trim() === '' || /[0-9\u4e00-\u9fa5]/.test(englishName)) {
                alert('英文名格式不正确');
                return;
            }

            // 判断邮箱格式是否正确
            if (!/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(email)) {
                alert('邮箱格式不正确');
                return;
            }

            // 判断联系电话格式是否正确
            if (!/^1[3456789]\d{9}$/.test(phone)) {
                alert('联系电话格式不正确');
                return;
            }

            // 判断生日是否为空
            if (bornDate.trim() == '') {
                alert('生日不能为空');
                return;
            }

            // 判断生日是否小于当前日期
            var currentDate = new Date();
            var selectedDate = new Date(bornDate);
            if (selectedDate > currentDate) {
                alert('生日不能大于当前日期');
                return;
            }

            // 发送保存请求
            $.ajax({
                url: "http://localhost:8080/employee/addController",
                type: "POST",
                data: {
                    name: name,
                    englishName: englishName,
                    email: email,
                    phone: phone,
                    gender: gender,
                    bornDate: bornDate,
                    token: token,
                    longToken: longToken
                },
                dataType: "json",
                success: function (data) {
                    if (data.code == 200) {
                        alert("保存成功");
                        window.location.href = "employee-list.html";
                    } else if (data.code == 4000) {
                        // 跳转到登录页面
                        window.location.href = 'employee-login.html';
                    } else {
                        alert(data.msg);
                    }
                },
                error: function () {
                    alert("保存失败");
                }
            });
        }


        $(document).ready(function () {
            // 选择框
            $(".select2").select2();

            // WYSIHTML5编辑器
            $(".textarea").wysihtml5({
                locale: 'zh-CN'
            });

            var token = localStorage.getItem('token');
            var longToken = localStorage.getItem('longToken');

            if (!(token && longToken)) {

                // 跳转到登录页面
                window.location.href = 'employee-login.html';
            }
        });


        // 设置激活菜单
        function setSidebarActive(tagUri) {
            var liObj = $("#" + tagUri);
            if (liObj.length > 0) {
                liObj.parent().parent().addClass("active");
                liObj.addClass("active");
            }
        }



        $(document).ready(function () {

            // 颜色选取器
            $(".my-colorpicker1").colorpicker();
            $(".my-colorpicker2").colorpicker();

        });




        $(document).ready(function () {
            // 选择框
            $(".select2").select2();
        });




        $(document).ready(function () {

            //Date picker
            $('#datepicker').datepicker({
                autoclose: true,
                language: 'zh-CN'
            });

            // datetime picker
            $('#dateTimePicker').datetimepicker({
                format: "mm/dd/yyyy - hh:ii",
                autoclose: true,
                todayBtn: true,
                language: 'zh-CN'
            });

            //Date range picker
            $('#reservation').daterangepicker({
                locale: {
                    applyLabel: '确认',
                    cancelLabel: '取消',
                    fromLabel: '起始时间',
                    toLabel: '结束时间',
                    customRangeLabel: '自定义',
                    firstDay: 1
                },
                opens: 'left', // 日期选择框的弹出位置
                separator: ' 至 '
                //showWeekNumbers : true,     // 是否显示第几周
            });

            //Date range picker with time picker
            $('#reservationtime').daterangepicker({
                timePicker: true,
                timePickerIncrement: 30,
                format: 'MM/DD/YYYY h:mm A',
                locale: {
                    applyLabel: '确认',
                    cancelLabel: '取消',
                    fromLabel: '起始时间',
                    toLabel: '结束时间',
                    customRangeLabel: '自定义',
                    firstDay: 1
                },
                opens: 'right', // 日期选择框的弹出位置
                separator: ' 至 '
            });

            //Date range as a button
            $('#daterange-btn').daterangepicker({
                locale: {
                    applyLabel: '确认',
                    cancelLabel: '取消',
                    fromLabel: '起始时间',
                    toLabel: '结束时间',
                    customRangeLabel: '自定义',
                    firstDay: 1
                },
                opens: 'right', // 日期选择框的弹出位置
                separator: ' 至 ',
                ranges: {
                    '今日': [moment(), moment()],
                    '昨日': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                    '最近7日': [moment().subtract(6, 'days'), moment()],
                    '最近30日': [moment().subtract(29, 'days'), moment()],
                    '本月': [moment().startOf('month'), moment().endOf('month')],
                    '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                },
                startDate: moment().subtract(29, 'days'),
                endDate: moment()
            },
                function (start, end) {
                    $('#daterange-btn span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
                }
            );

        });


        $(document).ready(function () {

            /*table tree*/
            $("#collapse-table").treetable({
                expandable: true
            });

        });

        $(document).ready(function () {

            // 激活导航位置
            setSidebarActive("admin-datalist");

        });
    </script>
</body>

</html>